package lp.xian.materials.controller;

import java.text.ParseException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import lp.xian.materials.domain.RequisitionTable;
import lp.xian.materials.vo.ReqVo;
import lp.xian.materials.vo.RequisitionVo;
import lp.xian.materials.vo.WarehouseWarrantVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import lp.xian.materials.domain.Requisition;
import lp.xian.materials.service.IRequisitionService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请购计划Controller
 *
 * @author ruoyi
 * @date 2023-08-05
 */
@RestController
@RequestMapping("/requisition/requisition")
public class RequisitionController extends BaseController
{
    @Autowired
    private IRequisitionService requisitionService;

    /**
     * 审批采购订单列表
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:audit')")
    @Log(title = "审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult auditRequisition (@RequestBody RequisitionVo requisitionVo) throws ParseException
    {
        return toAjax(requisitionService.auditRequisition(requisitionVo));
    }

    /**
     * 查询请购计划列表
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:list')")
    @GetMapping("/list")
    public TableDataInfo list(Requisition requisition)
    {
        startPage();
        List<Requisition> list = requisitionService.selectRequisitionList(requisition);
        return getDataTable(list);
    }

    /**
     * 导出请购计划列表
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:export')")
    @Log(title = "请购计划", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Requisition requisition)
    {
        List<Requisition> list = requisitionService.selectRequisitionList(requisition);
        ExcelUtil<Requisition> util = new ExcelUtil<Requisition>(Requisition.class);
        util.exportExcel(response, list, "请购计划数据");
    }

    /**
     * 获取请购计划详细信息
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:query')")
    @GetMapping(value = "/{requisitionId}")
    public AjaxResult getInfo(@PathVariable("requisitionId") Integer requisitionId)
    {
        return success(requisitionService.selectRequisitionByRequisitionId(requisitionId));
    }

    /**
     * 新增请购计划
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:add')")
    @Log(title = "请购计划", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ReqVo reqVo)
    {
        return toAjax(requisitionService.insertRequisition(reqVo));
    }

    /**
     * 修改请购计划
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:edit')")
    @Log(title = "请购计划", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Requisition requisition)
    {
        return toAjax(requisitionService.updateRequisition(requisition));
    }

    /**
     * 删除请购计划
     */
    @PreAuthorize("@ss.hasPermi('requisition:requisition:remove')")
    @Log(title = "请购计划", businessType = BusinessType.DELETE)
    @DeleteMapping("/{requisitionIds}")
    public AjaxResult remove(@PathVariable Integer[] requisitionIds)
    {
        return toAjax(requisitionService.deleteRequisitionByRequisitionIds(requisitionIds));
    }
}
